package com.fengxu.gamescript.ui.reg

import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.JavascriptInterface
import android.webkit.WebView
import com.fengxu.gamescript.R
import com.fengxu.gamescript.ui.base.BaseActivity
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.find
import org.jetbrains.anko.toast

class RegisterActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_register)
        initView()
    }

    @SuppressLint("JavascriptInterface")
    fun initView(){
        var webView = find<WebView>(R.id.reg_webView)
        webView.settings.javaScriptEnabled = true
        webView.settings.domStorageEnabled = true
        webView.addJavascriptInterface(this, "Android")
        webView.loadUrl("http://47.96.229.28:8080/index.html")
    }

    /**
     * 注册成功的回调
     */
    @JavascriptInterface
    fun success(email: String, pwd: String){
        toast("操作成功，1秒后回到登录页!")
        doAsync {
            Thread.sleep(1000)
            val intent = Intent()
            intent.putExtra("email",email)
            intent.putExtra("pwd",pwd)
            setResult(100,intent)
            finish()
        }
    }
}